package org.mspring.platform.web.listener;

import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Trace the HttpSession event, for debug.
 *
 * @author gaoyb(www.mspring.org)
 * @since Mar 5, 2011
 */
public class SessionTraceListener implements HttpSessionListener, HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionActivationListener {

    private static final Logger logger = LoggerFactory.getLogger(SessionTraceListener.class);

    @Override
    public void sessionCreated(HttpSessionEvent sessionEvent) {
        logger.debug("sessionCreated, sessionid=" + sessionEvent.getSession().getId());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent sessionEvent) {
        logger.debug("sessionDestroyed, sessionid=" + sessionEvent.getSession().getId());
    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent bindingEvent) {
        logger.debug("attributeAdded, bindingEvent[name=" + bindingEvent.getName() + ", value=" + bindingEvent.getValue() + "]");
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent bindingEvent) {
        logger.debug("attributeRemoved, bindingEvent[name=" + bindingEvent.getName() + ", value=" + bindingEvent.getValue() + "]");
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent bindingEvent) {
        logger.debug("attributeReplaced, bindingEvent[name=" + bindingEvent.getName() + ", value=" + bindingEvent.getValue() + "]");
    }

    @Override
    public void valueBound(HttpSessionBindingEvent bindingEvent) {
        logger.debug("valueBound, bindingEvent[name=" + bindingEvent.getName() + ", value=" + bindingEvent.getValue() + "]");
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent bindingEvent) {
        logger.debug("valueUnbound, bindingEvent[name=" + bindingEvent.getName() + ", value=" + bindingEvent.getValue() + "]");
    }

    @Override
    public void sessionDidActivate(HttpSessionEvent sessionEvent) {
        logger.debug("sessionDidActivate, sessionid=" + sessionEvent.getSession().getId());
    }

    @Override
    public void sessionWillPassivate(HttpSessionEvent sessionEvent) {
        logger.debug("sessionWillPassivate, sessionid=" + sessionEvent.getSession().getId());
    }

}
